package com.mqtt.demo2.controller;

import com.alibaba.fastjson.JSON;
import com.mqtt.demo1.damain.User;
import com.mqtt.demo2.constant.TopicConstant;
import com.mqtt.demo2.producer.MqttTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author renyitong
 * @version 1.0.0
 * @createTime 2023年09月01日
 * @Description
 */
@RestController
public class MessageController {

    @Autowired
    private MqttTemplate mqttTemplate;

    @GetMapping("/message/send")
    public String sendMsg(){
        User user = new User();
        user.setUsername("周杰伦");
        user.setPassword("zhouzhoumiao");
        user.setAge(44);
        user.setDescription("哎呦不错哟,奶茶我只喝优乐美!");
        String jsonString = JSON.toJSONString(user);
        mqttTemplate.sendToTopic(jsonString, TopicConstant.VTM_REBOOT.getTopic(),2);
        return "success";
    }

}
